//
//  MineViewController.m
//  NineGroupProject
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 lushan. All rights reserved.
//

#import "MineViewController.h"
#import <Masonry.h>
#import <SDImageCache.h>
#import "CollectionViewController.h"
@interface MineViewController ()

@property (nonatomic, retain)UIButton *nightBtn;
@property (nonatomic, retain)UIButton *cacheBtn;
@property (nonatomic, retain)UIButton *collectBtn;
@property (nonatomic, retain)UIButton *aboutBtn;

@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UILabel *customLab = [[UILabel alloc] initWithFrame:CGRectZero];
    [customLab setTextColor:[UIColor whiteColor]];
    [customLab setText:@"我的"];
    customLab.textAlignment = NSTextAlignmentCenter;
    customLab.font = [UIFont boldSystemFontOfSize:20];
    [customLab sizeToFit];
    self.navigationItem.titleView = customLab;
    
    UIImageView *bgImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgImg.png"]];
    bgImg.backgroundColor = [UIColor blackColor];
    [self.view addSubview:bgImg];
    
    [bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.equalTo(self.view.mas_height).multipliedBy(0.4);
    }];
    
    self.collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
    [self.collectBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self.collectBtn addTarget:self action:@selector(collectAction:) forControlEvents:UIControlEventTouchUpInside];
    self.collectBtn.layer.borderWidth = 1;
    self.collectBtn.layer.borderColor = [UIColor colorWithRed:231 / 255.0 green:231 / 255.0 blue:231 / 255.0 alpha:1].CGColor;
    [self.collectBtn setImage:[UIImage imageNamed:@"iconfont-iconfontshoucang.png"] forState:UIControlStateNormal];
    [self.view addSubview:self.collectBtn];
    
    [_collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgImg.mas_bottom).offset(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.equalTo(bgImg.mas_height).multipliedBy(0.25);
    }];
    
    self.cacheBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.cacheBtn setTitle:@"清除缓存" forState:UIControlStateNormal];
    [self.cacheBtn addTarget:self action:@selector(cacheAtion:) forControlEvents:UIControlEventTouchUpInside];
    [self.cacheBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.cacheBtn.layer.borderWidth = 1;
    self.cacheBtn.layer.borderColor = [UIColor colorWithRed:231 / 255.0 green:231 / 255.0 blue:231 / 255.0 alpha:1].CGColor;
    [self.cacheBtn setImage:[UIImage imageNamed:@"iconfont-qingchuyuhuancun.png"] forState:UIControlStateNormal];
    [self.view addSubview:self.cacheBtn];
    
    [_cacheBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_collectBtn.mas_bottom).offset(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.equalTo(bgImg.mas_height).multipliedBy(0.25);
    }];
    
}
- (void)collectAction:(UIButton *)btn{
    CATransition *transition = [CATransition animation];
    transition.duration = 1.0f;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    transition.type = @"rippleEffect";
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];
    CollectionViewController *collectionVC = [[CollectionViewController alloc] init];
    collectionVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:collectionVC animated:YES];
}
- (void)cacheAtion:(UIButton *)btn{
    //    获取SDWebImage 缓存图片的大小
    NSUInteger size = [[SDImageCache sharedImageCache]getSize];
    float chcheSize = size / 1024.0 / 1024.0;
    NSString *cachesStr = [NSString stringWithFormat:@"已经为您清除 %.2fM 缓存", chcheSize];
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"是否清除缓存" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *othact = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        //    清除缓存
        [[SDImageCache sharedImageCache]clearDisk];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:cachesStr preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *othact = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        }];
        [alert addAction:othact];
        [self presentViewController:alert animated:YES completion:nil];
        
    }];
    UIAlertAction *canact = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];
    [alert addAction:othact];
    [alert addAction:canact];
    [self presentViewController:alert animated:YES completion:nil];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
